package com.haoshuang.zhouzhoubang.ui.page.shop.order.child


import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter4.BaseQuickAdapter
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ItemShopOrderBinding
import com.haoshuang.zhouzhoubang.model.bean.OrderBean8
import com.haoshuang.zhouzhoubang.ui.page.shop.order.detail.ShopOrderDetailActivity
import com.mufeng.libs.base.BaseBindingHolder
import com.mufeng.libs.base.BaseBindingQuickAdapter
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.view.gone
import com.mufeng.libs.utils.view.visible


/**
 * 订单模块中的订单列表适配器
 * */
class ShopOrderListAdapter(data: MutableList<OrderBean8>) :
    BaseBindingQuickAdapter<OrderBean8, ItemShopOrderBinding>(data){

    override fun onBindViewHolder(holder: BaseBindingHolder, position: Int, item: OrderBean8?) {
        val binding = ItemShopOrderBinding.bind(holder.itemView)
        binding.apply {
            var adapter= item?.cartInfo?.let { ShopOrderListAdapter2(it) }
            rvList2.layoutManager=LinearLayoutManager(context)
            rvList2.adapter=adapter
            tvTime.text="下单时间：${item?.add_time}"
            adapter?.setOnItemClickListener { adapter, view, position ->
                context.startPage<ShopOrderDetailActivity>("ids" to item?.id)
            }
            //0待支付1待发货2待收货3已完成4已取消
            when(item?.status){
                0->{
                    tvState.text="待付款"
                    tvLeftButton.visible()
                    tvRightButton.visible()
                    tvRightButton.text="立即支付"
                }
                1->{
                    tvState.text="待发货"
                    tvLeftButton.gone()
                    tvRightButton.gone()
                    // tvRightButton.text="立即支付"
                }
                2->{
                    tvState.text="待收货"
                    tvLeftButton.gone()
                    tvRightButton.visible()
                    tvRightButton.text="确认收货"
                }
                3->{
                    tvState.text="已完成"
                    tvLeftButton.gone()
                    tvRightButton.gone()
                }
                4->{
                    tvState.text="已取消"
                    tvLeftButton.gone()
                    tvRightButton.gone()
                }
                else->{
                    tvState.text="已完成"
                    tvLeftButton.gone()
                    tvRightButton.gone()
                }
            }
        }

    }

}